package com.tools;

import java.util.logging.Logger;

/**
 * 协议处理中的一些工具类
 * 
 * @author zhu@goome 2010/03/27
 *
 */
public class ProtocolUtil {
	
	/** log4j */
	//private static final Logger log = Logger.getLogger(ProtocolUtil.class);
	
	/**
	 * 把16进制的时间转换成常规日期时间
	 * 
	 * @param hexDateTime 终端上来的16进制时间
	 * @return
	 */
	public static  String getSimpleFormatDateTime(String hexDateTime) {
		int[] iDateTiem = new int[6];

		for (int j = 1; j <= 6; j++) {
			iDateTiem[j - 1] = Integer.parseInt(hexDateTime.substring(
					(j - 1) * 2, j * 2), 16);
		}

		String head = "20";
		if ((iDateTiem[0] + "").length() == 1)
			head = "200";
		return head + iDateTiem[0] + "-" + iDateTiem[1] + "-" + iDateTiem[2]
				+ " " + iDateTiem[3] + ":" + iDateTiem[4] + ":" + iDateTiem[5];
	}
	
	/**
	 * 将16进制字符串转成2进制字符串
	 * 
	 * @param addInfo 数据(16进制)
	 * @param length 目标byte的位数
	 * @return
	 */
	
	public static String str2ByteString(String addInfo,int length){
		// 获得状态位
		int status = Integer.parseInt(addInfo, 16);
		// 转换成字节位
		String str2 = Integer.toBinaryString(status);
		// 将2个字节补满，左补0
		//str2 = StringUtil.lefgPadding(str2, '0', length);
		str2="0000000000000000"+str2;
		int len=str2.length()-16;
		str2=str2.substring(len,16);
		return str2;
	}
}